package org.example;

import java.util.ArrayList;
import java.util.List;

public class Player {


    /**
     * 玩家名字
     */
    private String name;

    /**
     * 玩家拥有的扑克牌信息
     */
    private List<PokeBean> pokeBeans = new ArrayList<>();


    /**
     * 角色
     */
    private RoleEnum role;


    /**
     * 拥有的扑克牌A的数量
     */
    private Integer sumOfA = 0;

    /**
     * 玩家的分数
     */
    private List<Integer> score = new ArrayList<>();

    /**
     * 最大有效分数
     */
    private Integer maxScore;

    /**
     * 游戏参与状态
     */
    private GameJoinEnum gameJoinStatus = GameJoinEnum.UNDER_WAY;



    public Player(String name, RoleEnum role) {
        this.name = name;
        this.role = role;
    }


    public GameJoinEnum getGameJoinStatus() {
        return gameJoinStatus;
    }

    public void setGameJoinStatus(GameJoinEnum gameJoinStatus) {
        this.gameJoinStatus = gameJoinStatus;
    }

    public Integer getMaxScore() {
        return maxScore;
    }

    public void setMaxScore(Integer maxScore) {
        this.maxScore = maxScore;
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<PokeBean> getPokeBeans() {
        return pokeBeans;
    }

    public void setPokeBeans(List<PokeBean> pokeBeans) {
        this.pokeBeans = pokeBeans;
    }

    public Integer getSumOfA() {
        return sumOfA;
    }

    public void setSumOfA(Integer sumOfA) {
        this.sumOfA = sumOfA;
    }

    public List<Integer> getScore() {
        return score;
    }

    public void setScore(List<Integer> score) {
        this.score = score;
    }

    public RoleEnum getRole() {
        return role;
    }

    public void setRole(RoleEnum role) {
        this.role = role;
    }

    public String getPokeBeansShow() {
        StringBuilder sb = new StringBuilder();
        for (PokeBean pokeBean : pokeBeans) {
            if (pokeBean.getShow()) {
                sb.append(pokeBean.getColor().getDesc()).append(pokeBean.getName());
            } else {
                sb.append("🎴");
            }
            sb.append(" ");
        }
        return sb.toString();
    }

    public void addPoke(PokeBean poke) {
        if (poke.getName().equals("A")) {
            this.sumOfA++;
        }
        this.pokeBeans.add(poke);
        // 点数统计自检 并动态记录分数
        Integer minScore = GameUtil.countPoints(this.pokeBeans);
        if (minScore > 21){
            // 爆牌
            this.gameJoinStatus = GameJoinEnum.REVEAL_CARDS;
        }
        this.score.clear();
        this.score.add(minScore);
        for (int i = 0; i < this.sumOfA; i++) {
            if (minScore + 10 <=  21) {
                this.score.add(minScore + 10);
            }
        }
        this.maxScore = GameUtil.getMaxScore(this);
        GameUtil.showPlayerPoke(this);
    }
}
